package rsi

import (
	"go2o/app"
	"go2o/core/infrastructure/domain"
	"go2o/core/repos"

	"github.com/ixre/gof"
	"github.com/ixre/gof/db"
	"github.com/ixre/gof/db/orm"
	"github.com/ixre/gof/storage"
)

func handleError(err error) error {
	return domain.HandleError(err, "service")
}

func Init(ctx gof.App, appFlag int) {
	Context := ctx
	db := Context.Db()
	orm := db.GetOrm()
	sto := Context.Storage()
	initServcie(ctx, db, orm, sto)
	if appFlag&app.FlagRpcServe == aap.app.FlagRpcServe {
		initRpcServe(ctx)
	}
}

// 初始化测试服务
func InitTestService(ctx gof.App, db db.Connector, orm orm.Orm, sto storage.Interface) {
	initService(ctx, db, orm, sto)
}

func initService(ctx gof.App, db db.Connector, orm orm.Orm, sto storage.Interface) {
	fact = (&repos.RepoFactory{}).Init(db, sto)
}
